package c1702;

import java.util.Arrays;
import java.util.Scanner;


public class J {

     static Scanner cin = new Scanner(System.in);
    public static void main(String[] args) {

        int T = cin.nextInt();
        while (T-- > 0) {
            int n = cin.nextInt();

            Pipe[] pipes = new Pipe[n];
            for (int i = 0; i < n; i++) {
                int length = cin.nextInt();
                int diameter = cin.nextInt();
                int number = cin.nextInt();
                pipes[i] = new Pipe(length, diameter, number);
            }
            Arrays.sort(pipes);
            System.out.println(pipes[0].number);

        }

    }

    static class Pipe implements Comparable<Pipe> {
        int length;
        int diameter;
        int number;

        public Pipe(int length, int diameter, int number) {
            this.length = length;
            this.diameter = diameter;
            this.number = number;
        }

        public int compareTo( Pipe that) {
            if (this.length != that.length)
                return that.length - this.length;//按照长度排降序
            if (this.diameter != that.diameter)
                return this.diameter - that.diameter;//按照直径排升序
            return that.number - this.number;
        }
    }
}